// 主界面
;define(function(require, exports, module) {
    'use strict';
    var util = require("util");
    var base = require(CONFIG.BasePath + "js/enterprise/base");
    var router = require("../hash/pageRouter");
    var top = require("../top/top_main");
    var footer = require("../footer/footer_main");
    var pageIndex = 1,
        pageSize = 5,
        totalPageCount = 1,
        totalRecordCount = 0; //分页初始化
    var keyword;
    var init = function(){
    	keyword = decodeURI(decodeURI(base.getUrlParam("keyword")));
    	if(keyword!="null" && keyword!=undefined){
    		$("#helpContent").val(keyword);
    	}
    	
    	inquireHelpPageList();
    	router.init();
		initEvent(); 
    };
    
	var initEvent = function(){
	$(".search").on("click",function(){
		inquireHelpPageList();
		
	});
	//点击首页
	$(".main").on("click",function(){
		location.href="../main/main.html";
	});
    };
   
	
	//查询资讯列表
    var inquireHelpPageList = function(){
    	var content = $("#helpContent").val();
		base.fnAjax({
			action: "inquireHelpPageList.json",
			nocode: true,
			oData: {
				pageIndex:pageIndex,
				pageSize: pageSize,
				content:content
            }, //传递参数
            fnSuccess: function(data) {
                if (data.status == 200) {
                	var tpl = $("#helpPageListTpl").html();
                	var html = juicer(tpl, data);
                	$(".helpContenter").find("dd").remove();
                	$(".helpContenter").append(html);
                	 totalPageCount = data.totalPageCount;
                    totalRecordCount = data.totalRecordCount;
                    base.pageControl(
                    	$("#pagenation"),
                        totalRecordCount,
                        data.pageIndex,
                        data.pageSize,
                        function(p) {
                            pageIndex = p;
                            inquireHelpPageList();
                    });
                    
                    $(".detail").unbind("click").click(function(){
                    	var newsId = $(this).attr("id");
                    	location.href = "./help_detail.html?newsId="+newsId;
                    });
                } else {
                	base.alert(3,data.message);
                }
            }
		});
	};

    return {
        init:init
    };
});